<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <%layout("/WEB-INF/view/common/inc/admin_head.html",{title:'', styles:'bootstrap,font-awesome,animate,style,bootstrap-table,layui'}){%>
    <style type="text/css">
        body{padding-top:10px;padding-left: 10px}
        *{margin:0;padding:0;list-style-type:none;}
        a,img{border:0;}
        .demo h2{font-size:16px;color:#3366cc;height:30px;}
        .demo li{float:left;}
        .has-no{color:#3366cc;}
        .has-success{color: #1ab394;}
        .has-warning{color: #f8ac59;}
        .has-error{color: #ed5565;}
        .remark {
            width: 100%; /*自动适应父布局宽度*/
            overflow: auto;
            word-break: break-all;
        }
    </style>
    <%}%>
</head>

<body>
<div class="wrapper wrapper-content">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins" style="margin-bottom: 0px;">
                <input type="hidden" readonly id="productMember" name="productMember" class="form-control" value="${user.userRealname}">
                <div class="ibox-content" style="padding:15px 20px 0px 20px;">
                    <form id="search-form" role="form" class="form-horizontal" autocomplete="off">
                        <div class="form-group">
                            <label class="control-label col-sm-1">渠道:</label>
                            <div class="col-sm-2">
                                <select  name="salesChannelName" id="salesChannelName" class="form-control">
                                    <option value="">请选择渠道</option>
                                    <%for(var dict in channel){%>
                                    <option value="${dict.channelName}"  >${dict.channelName}</option>
                                    <%}%>
                                </select>
                            </div>
                            <label class="control-label col-sm-1">SKU:</label>
                            <div class="col-sm-2">
                                <input type="text" name="salesSku" id="salesSku" placeholder="请填写SKU" class="form-control">
                            </div>
                            <label class="control-label col-sm-1">ASIN:</label>
                            <div class="col-sm-2">
                                <input type="text" name="salesAsin" id="salesAsin" placeholder="请填写ASIN" class="form-control">
                            </div>
                        </div>
                        <div class="form-group">

                            <label class="control-label col-sm-1">Listing:</label>
                            <div class="col-sm-2">
                                <input type="text" name="salesListing" id="salesListing" placeholder="请填写Listing" class="form-control">
                            </div>
                            <a class="search-btn btn btn-success" style="margin-bottom: 0px;">查询</a>
                        </div>
                    </form>
                </div>
            </div>
        <div id="toolbar" class="btn-group" style="margin-bottom:5px;">
            <button  class="add-btn layui-btn layui-btn-normal layui-btn-sm" style="margin-top: -6px;margin-left: -4px" id="import-btn"  name="import-btn">
                <i class="fa fa-plus" aria-hidden="true"></i> 导入预测销量
            </button>
            &nbsp;
            <button  class="import-stock-btn layui-btn layui-btn-danger layui-btn-sm" style="margin-top: -6px;margin-left: -4px" id="import-stock-btn"  name="import-stock-btn">
                <i class="fa fa-plus" aria-hidden="true"></i> 导入FBA库存
            </button>
            &nbsp;
            <button  class="layui-btn  layui-btn-sm" style="margin-top: -6px;margin-left: -2px">
                <i class="fa fa-download"></i>
                <a href="/excel/销量预测模板.xlsx" style="color: white" download>模板下载</a>
            </button>
            &nbsp;
            <button  class="export-btn layui-btn  layui-btn-sm" style="margin-top: -6px;margin-left: -2px">
                <i class="fa fa-download" aria-hidden="true"></i> 导出当前数据
            </button>
            <button  class="reset-btn layui-btn  layui-btn-sm" style="margin-top: -6px;margin-left: -2px">
                <i class="fa fa-spinner" aria-hidden="true"></i> 清空当前数据
            </button>

        </div>
        <!-- START 右侧数据 -->
        <!-- START 数据表格 -->
        <table id="relatedTable"
               data-toolbar="#toolbar"
               data-side-pagination="server"
               data-pagination="true"
               data-resizable="true"
               data-side-pagination="server"
               data-url="/sea/data/sales/findByCnd"
               data-page-size="15"
               class="table table-striped table-hover"
        >
        </table>
        <!-- END 数据表格 -->

        </table>
        <!-- END 右侧数据 -->
    </div>
    </div>
</div>




<!-- START 内容部分 -->
<div class="container" style="display: none;overflow-x: hidden;max-width: 600px" id="layer_window">
    <form class="form-horizontal" id="info-form" enctype="multipart/form-data" autocomplete="off" >
        <input type="hidden" name="createId" id="id">

        <br/>

        <div class="form-group" style="max-width: 600px;min-width: 580px">
            <label class="control-label col-sm-2">选择文件:</label>
            <div class="col-sm-6">
                <a class="club-import-btn ">
                    <input type="file" id="importSession" name="importSession">
                </a>
            </div>
        </div>
        <div class="form-group" style="margin-top: 20px">
            <label class="category control-label col-sm-2" >日期</label>
            <div class="col-sm-6" style="max-width: 300px">
                <input type="text" id="salesDate" name="salesDate" value="" class="form-control">
            </div>
        </div>
        <div class="form-group" style="margin-top: 20px">
            <label class="category control-label col-sm-2" style="max-width: 100px">渠道</label>
            <div class="col-sm-6" style="max-width: 300px">
                <select  name="salesChannelName"  class="form-control">
                    <option value="">请选择渠道</option>
                    <%for(var dict in channel){%>
                    <option value="${dict.channelName}"  >${dict.channelName}</option>
                    <%}%>
                </select>
            </div>
        </div>
        <br/>

    </form>
    <div class="form-group">
        <div class="col-sm-offset-2 col-sm-10">
            <button type="submit" class="save-btn btn btn-primary">
                <i class="fa fa-save"></i> 保存
            </button>
        </div>
    </div>
</div>
<%layout("/WEB-INF/view/common/inc/admin_js.html",{modules:'jquery,bootstrap,bootstrap-table,dtvalidate,dtvalidate-lang-zh_cn,bootstrap-table-zh-CN,laydate,layer,layui,upload'}){}%>
<script>
    laydate.render({
        elem: '#salesDate',
        type: 'date',
        format: 'yyyy-MM-dd',
        trigger: 'click'
    });


    $('.save-btn').on('click',function(){
        layer.closeAll();
        layer.load();
        importExcel();
    });



    function importExcel() {
        $.ajax({
            url: "/sea/data/sales/importStock",
            data:  new FormData($('#info-form')[0]),
            type: "post",
            // async: false,
            processData: false,//用于对data参数进行序列化处理 这里必须false
            contentType: false, //必须
            beforeSend:function () {
                layer.closeAll();
                layer.load(1, {
                    shade: [0.1,'#fff'], //0.1透明度的白色背景
                    zIndex : 1
                });
            },
            success: function (data) {
                if(data.ok){
                    layer.closeAll();
                    layer.msg("上传成功！",{icon: 0,time:1500,shade: [0.8, '#393D49']});
                    $relatedTable.bootstrapTable('refresh');

                }else{
                    layer.closeAll(); //关闭弹窗
                    layer.msg(data.msg,{icon: 0,btn: ['确定'],time:0,shade: [0.8, '#393D49'],yes: function(index, layero){
                            layer.closeAll();
                        }});
                }
            },
            error:function (data) {
                layer.msg("接口异常!请联系管理员!",{icon: 0,btn: ['确定'],time:0,shade: [0.8, '#393D49'],yes: function(index, layero){
                        layer.closeAll();
                    }});
            }
        });
    }

    var $relatedTable = $('#relatedTable'),selections=[];
    $(function(){
        //START 表格配置
        $relatedTable.bootstrapTable({
            columns: [
                {
                    title: 'Listing',
                    field: 'salesListing',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '渠道',
                    field: 'salesChannelName',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: 'FNSKU',
                    field: 'salesFnsku',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: 'SKU',
                    field: 'salesSku',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: 'ASIN',
                    field: 'salesAsin',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '日期',
                    field: 'salesDate',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '日均销量',
                    field: 'salesNumber',
                    align: 'center',
                    valign: 'middle'
                },

                {
                    title: '海运入库',
                    field: 'salesPhysicalNumber',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '采购入库',
                    field: 'salesProduceNumber',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '期末库存',
                    field: 'salesStock',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '海运入库(海外仓)',
                    field: 'salesStockPhysicalNumber',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '采购入库(海外仓)',
                    field: 'salesStockProduceNumber',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '可售库存',
                    field: 'salesSellNumber',
                    align: 'center',
                    valign: 'middle'
                }
            ],
            onLoadSuccess : function() {
                //删除数据字典详情信息
                $('.del-btn').on('click',function(){
                    var delid = $(this).attr('data-val'),delname = $(this).attr('data-val-no');
                    //删除提示
                    layer.confirm('确定要删除当前请购单？<br>['+delname+']', {
                        btn: ['确定','取消'],title:'提示'
                    }, function(){
                        $.post('/sea/data/order/delete.do',{id: delid},function(data){
                            if( data.ok ){
                                layer.msg(data.msg,{icon: 1,time: 1500},function(){
                                    //刷新页面
                                    $relatedTable.bootstrapTable('refresh');
                                });
                            }else{
                                layer.msg(data.msg,{icon: 0,time: 1500});
                            }
                        });
                    });
                });
            },
            onExpandRow: function (index, row, $detail) {
                InitSubTable(index, row, $detail);
            }
        })

    });

    $(".import-stock-btn").on('click',function () {
        var id = $(this).attr('data-val');
        $("#id").val(id);
        layer.open({
            type:1,
            title:'导入明细',
            area:['600px','400px'],
            skin:'layer-window',
            shadeClose:false,
            resize: false,
            scrollbar: false,
            maxmin: false,//出现最大化按钮
            content:$('#layer_window')
        });
    });



    $('.search-btn').on('click',function(){
        $relatedTable.bootstrapTable('refresh', { url:'${ctxPath}/sea/data/sales/findByCnd.do?'+$('#search-form').serialize() });
    });

    layui.use('upload', function(){
        var upload = layui.upload;
        upload.render({
            elem: '#import-btn', //绑定元素,
            accept:'file',
            url: '/sea/data/sales/import/', //上传接口
            data:{"productMember":$("#productMember").val()},
            before:function () {
                layer.load(1, {
                    shade: [0.1,'#fff'] //0.1透明度的白色背景
                });
            }
            ,done: function(data){
                if( data.ok ){
                    layer.msg(data.msg,{icon: 1,time: 1500},function(){
                        //刷新页面
                        $relatedTable.bootstrapTable('refresh');
                        layer.closeAll();
                    });
                }else{
                    layer.msg(data.msg,{icon: 0,time: 5000},function () {
                        layer.closeAll();
                    });

                }
            }
            ,error: function(){
                //请求异常回调
                layer.closeAll();
            }
        });
    });

    $(".export-btn").click(function () {
        window.location.href='/sea/data/sales/export.do?'+$('#search-form').serialize();
    });
    $(".reset-btn").click(function () {
        layer.confirm('确定要清空当前数据？', {
            btn: ['确定','取消'],title:'提示'
        }, function(){
            layer.closeAll();
            layer.load();
            $.post('/sea/data/sales/reset.do',function(data){
                if( data.ok ){
                    layer.msg(data.msg,{icon: 1,time: 1500},function(){
                        //刷新页面
                        $relatedTable.bootstrapTable('refresh');
                        layer.closeAll();
                    });
                }else{
                    layer.closeAll(); //关闭弹窗
                    layer.msg(data.msg,{icon: 0,btn: ['确定'],time:0,shade: [0.8, '#393D49'],yes: function(index, layero){
                            layer.closeAll();
                        }});
                }
            });
        });
    });

</script>
</body>
</html>
